#include "MobileObject.h"

#include "Boss.h"
#include "Player.h"
#include "..\Tile Management\Tile.h"


MobileObject::MobileObject()
{
	float r = GetSize().width / 2.0f;

	fMaxSpeed = 100;
	acceleration = SGD::Vector{ 10, 0 };
}


MobileObject::~MobileObject()
{
}

int MobileObject::Update(float dt)
{
	// Apply acceleration to velocity
	SetVelocity(GetVelocity() + GetAcceleration() * dt);

	if (GetVelocity().ComputeLength() > GetMaxSpeed())
		SetVelocity(GetVelocity().ComputeNormalized() * GetMaxSpeed());

	// Apply velocity to position
	SetPosition(GetPosition() + GetVelocity() * dt);
	
	// Restraint for Lock Jaw only
	if (GetID() == GameObject::ObjectID::LOCKJAW)
	{
		Boss* lockjaw = dynamic_cast<Boss*>(this);
		if (GetPosition().x <= lockjaw->GetPatrolPointLeft().x && !(GAME->GetPlayer()->GetPosition().x > lockjaw->GetPosition().x))
		{
			SetVelocity(SGD::Vector{ 0.0f, 0.0f });
			SetAcceleration(SGD::Vector{ 0.0f, 0.0f });
			SetPosition(SGD::Point{ lockjaw->GetPatrolPointLeft().x, GetPosition().y });
			SetAnimation("LockJawStandingLeft");
		}
	}
	// Call Game Object Update
	GameObject::Update(dt);

	return 0;
}

void MobileObject::HandleCollision(const GameObject* collision)
{

}

// Accessors
float MobileObject::GetMaxSpeed()
{
	return fMaxSpeed;
}

SGD::Vector MobileObject::GetVelocity()const
{
	return velocity;
}

SGD::Vector MobileObject::GetAcceleration()const
{
	return acceleration;
}

int MobileObject::GetDamage() const
{
	return iDamage;
}

bool MobileObject::GetIsKilled() const
{
	return IsKilled;
}

// Mutators
void MobileObject::SetMaxSpeed(float speed)
{
	fMaxSpeed = speed;
}

void MobileObject::SetVelocity(SGD::Vector v)
{
	velocity = v;
}

void MobileObject::SetAcceleration(SGD::Vector a)
{
	acceleration = a;
}

void MobileObject::SetDamage(int damage)
{
	iDamage = damage;
}

void MobileObject::SetIsKilled(bool isKilled)
{
	IsKilled = isKilled;
}